<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    //创建对象的方式

    //1：new Object
        //var person = new Object()
        //person.name = "list"
        //person.age = 10
        //person.say = function(){
        //    alert(this.name)
        //}
        //console.log(person);
    
    //2.字面量的方式
    //var person = {
    //    name:"lisi",
    //    age:19,
    //    say(){
    //        alert(this.name)
    //    }
    //}
    //console.log(person);//{name: 'lisi', age: 19, say: ƒ}

    //3:工厂模式创建对象  设计模式：单例模式 发布者-订阅者模式
    function CreatePerson(name,age,family){
        let o =new Object();
        o.name = name;
        o.age=age;
        o.family = family;
        o.say = function(){
            alert(this.name)
        }
        return o;
    }

     var person1 = CreatePerson("lisi",19,["King","queen","tom"])
     person1.say();
     var person2 = CreatePerson("wangwu",29,["jack","queen","tom"])
     person2.say();

    // 创造出大批类似的对象

// 构造函数 构造函数对象时调用的函数 但是构造函数只能调用一次 作用是给对象做初始化 普通函数 功能的封装 能多次调用

class User{ //
    //constructor ()//构造函数
    constructor(name,password){
        this.name = name;
        this.password = password
    }
    showName(){
        console.log(this.name);
    }
    showPassword(){
        console.log(this.password);
    }
}
var u1 = new User("king",123456)
u1.showName()
u1.showPassword()
console.log(typeof u1);
console.log(typeof User);

//ts按照类方式写
</script>
</html>